package com.qsign.sfrz_android.net;

import android.os.Handler;
import android.os.Message;
import android.util.Log;

import org.json.JSONException;
import org.json.JSONObject;

public class IServiceImpl {

	public static final String TAG = "IServiceImpl";
	public static final int LOGIN = 1;
	public static final int FH_QUERY = 2;
	public static final int RUKU_QUERY = 3;
	public static final int KUWEI_VALIDE = 4;
	public static final int RUKUIN = 5;
	public static final int CHUKU_QUERY= 6;
	public static final int CHUKUIN= 7;
	public static final int PRINTNO= 8;
	public static final int VALIDE_SHADAN= 9;
	public static final int PH_QUERY= 10;
	public static final int SHADAN_QUERY= 11;
	public static final int UPDATEAUTO= 12;
	public static final int PIHAOQUERY= 13;
	public static final int PIHAOITEMLIST= 14;
	public static final int PIHAOPRINT= 15;
	public static final int PIHAODELETE= 16;
	public static final int FUHEITEMCLICK= 17;
	public static final int PRINTITEM= 18;
	public static void callWebMethod(final Handler mHandler,
									 final int requestType, final Object inputInfo, final String methodName) {
		new Thread() {
			@Override
			public void run() {

				String jsonStr = WebServiceAccessUtils.newcall(methodName, inputInfo.toString());

				Message msg = Message.obtain();
				msg.what = requestType;
				msg.arg1 = 1;
				try {
					JSONObject json = new JSONObject(jsonStr);

					String falg = json.optString("OPT_FLAG");
					String info = json.optString("MSG_INFO");

					Log.d(TAG, "OnWebSercieRequest **** info=" + info);

					if (falg.equals("0")) {
						msg.arg1 = 0;
						if (info != null && info instanceof String
								&& info.startsWith("SUCCESS:")) {
							info = info.substring("SUCCESS:".length(),
									info.length());
						}
					} else {
						msg.arg1 = 1;
					}
					if (info != null) {
						msg.obj = info;
					}

					if (info != null && info instanceof String
							&& info.contains("FAILED")) {
						msg.arg1 = 1;
						msg.obj = info;
					}
				} catch (JSONException e) {
					msg.arg1 = 1;
					msg.obj = e.toString();
				}
				mHandler.sendMessage(msg);
			}
		}.start();
	}
}
